using System;
using System.Collections;
using System.Collections.Generic;
using GameFramework.common;
using GameFramework.events;
using GameFramework.timer;
using GameFramework.UI;
using UnityEngine;
using UnityEngine.UIElements;
using Event = UnityEngine.Event;

namespace Game.ui
{
    [View(SceneViewManagerName = SceneViewManagerNames.Home)]
    [Presenter(type = typeof(HomePresenter))]
    public class HomeView : BaseView
    {
        [UIBind(ClassName = "baseInfo")]
        private PlayerBaseInfo baseInfo;
        [UIBind(ClassName = "hero")]
        private Button menu_hero;
        [UIBind(ClassName = "war")]
        private Button menu_war;
        [UIBind(ClassName = "zhuangyuan")]
        private Button menu_zhuangyuan;
        [UIBind(ClassName = "setting")]
        private Button menu_setting;
        
        public override void init()
        {
            base.init();
            baseInfo.headImgClick += headImgClick;
        }

        public override void beforeShow()
        {
            base.beforeShow();
            //如果点击界面没反应了，可以先如下面这样注册下
            // menu_war.RegisterCallback<ClickEvent>(e =>
            // {
            //     Debug.Log("被点击");
            // });
            elementRegisterCallBack<ClickEvent>(menu_hero, ev => menu_heroClick());
            elementRegisterCallBack<ClickEvent>(menu_war, ev => menu_warClick());
            elementRegisterCallBack<ClickEvent>(menu_zhuangyuan, ev => menu_zhuangyuanClick());
            elementRegisterCallBack<ClickEvent>(menu_setting, ev => menu_settingClick());
        }

        public override void afterShow()
        {
            MVPEventManager.Instance.HomeView_V2P_MainPlayerShow?.Invoke();
        }

        private void menu_heroClick()
        {
            UIManager.Instance.show<HeroView>();
        }
        private void menu_warClick()
        {
            Debug.Log("战役被点击！");
            UIManager.Instance.show<WarView>();
        }
        private void menu_zhuangyuanClick()
        {

        }
        private void menu_settingClick()
        {

        }

        private void headImgClick()
        {
            //TODO 展示个人信息页面
            Debug.Log("个人信息页面展示！");
        }

        protected override void modelPrepared(object data)
        {
            if (!(data is BaseInfoData))
            {
                Debug.LogWarning("HomeView refresh data is not BaseInfoData");
                return;
            }
            var baseInfoData = data as BaseInfoData;
            baseInfo.PlayerName = baseInfoData.Name;
            baseInfo.HeadImg = baseInfoData.headIcon;
            baseInfo.NowHp = baseInfoData.nowExp+"";
            baseInfo.MaxHp = baseInfoData.maxExp+"";
        }
        

        public override void afterHide()
        {
            base.afterHide();
            MVPEventManager.Instance.HomeView_V2P_MainPlayerHide?.Invoke();
        }
    }
}


